//
//  XKMainViewController.swift
//  XK2WeiBo
//
//  Created by mac on 16/7/2.
//  Copyright © 2016年 陈肖坤. All rights reserved.
//

import UIKit

class XKMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        //自定义TabBar
        let tabBar = XKTabBar()
        
        //设置代理
        tabBar.XKDelegate = self
        
        //通过KVC给,系统的只读属性赋值
        setValue(tabBar, forKey: "tabBar")
         
        
        addChildViewController(XKHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(XKDiscoverTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(XKMessageTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(XKProflleTableViewController(), title: "我", imageName: "tabbar_profile")
    }

    func addChildViewController(_ Vc: UIViewController,title:String,imageName:String) {
        //设置title
        Vc.title = title
        //设置image
        Vc.tabBarItem.image = UIImage(named: imageName)
        Vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        
        let navC = UINavigationController(rootViewController: Vc)
        addChildViewController(navC)
    }
}

extension XKMainViewController:XKTabBarDelegate {
    func composeButtonClick() {
        print("弹出控制器")
    }
}
